<template>
  <div>
    <el-table :data="list" :show-header="false" style="width: 100%">
      <el-table-column class-name="main">
        <template v-slot="{ row }">
          <span class="message-title">{{ row.main }}</span>
        </template>
      </el-table-column>
      <el-table-column>
        <template v-slot="{ row }">
          <el-image :src="row.image[0] | imgurl" :preview-src-list="row.image | imgurl" />
        </template>
      </el-table-column>
      <el-table-column class-name="main">
        <template v-slot="{ row }">
          <el-rate :value="row.evaluate / 2" :max="5" disabled show-score text-color="#ff9900"> </el-rate>
        </template>
      </el-table-column>
      <el-table-column width="180">
        <template v-slot="{ row }">
          {{ row.createdAt | date }}
        </template>
      </el-table-column>
      <el-table-column width="240">
        <template v-slot="{ row }">
          <el-button type="text" icon="el-icon-view" @click="details(row)"> 查看详情 </el-button>
          <el-button type="text" icon="el-icon-circle-check" @click="read(row)"> 标为已读 </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button style="margin-top: 16px" icon="el-icon-circle-check" @click="read()"> 全部标为已读 </el-button>
  </div>
</template>

<script>
import { unread, read } from '@/api/user'
import { clientAddress } from '@/config'

export default {
  data() {
    return {
      list: [],
    }
  },
  methods: {
    async init() {
      const data = await unread()
      if (data.code !== 200) return this.$message.error('获取信息失败,刷新页面重试,错误码:' + data.code)
      this.list = data.data
    },
    details(row) {
      window.open(clientAddress + '/comment-reply?id=' + row.id)
    },
    async read(row) {
      await read({ ids: row ? [row.id] : undefined })
      this.init()
    },
  },
  created() {
    this.init()
  },
}
</script>

<style lang="scss" scoped></style>
